package com.example.mybatisplus.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mybatisplus.model.domain.Logs;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.mybatisplus.model.dto.LogDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lxp
 * @since 2024-07-17
 */
@Repository
public interface LogsMapper extends BaseMapper<Logs> {

    @Insert("INSERT INTO Logs(log_id, vio_id,operation_time,operator_aid,operation_type)\n"+
    "VALUES (#{logId},#{vioId},#{operationTime},#{operatorAid},#{operationType})")
    void insertAll(Logs log);
    @Select("SELECT log_id FROM logs ORDER BY log_id")
    List<String> getAllLogsId();

    @Select("SELECT vio_id FROM logs ORDER BY log_id")
    List<String> getAllLogsVioId();

    @Select("SELECT operator_aid FROM logs ORDER BY log_id")
    List<Integer> getAllLogsOperatorAid();

    @Select("SELECT operation_type FROM logs ORDER BY log_id")
    List<String> getAllOperationType();

    @Select("SELECT operation_time FROM logs ORDER BY log_id")
    List<LocalDateTime> getAllOperationTime();

    List<LogDTO> selectLogs(@Param("ew") QueryWrapper<Logs> queryWrapper);

    @Select("SELECT COALESCE(MAX(CAST(SUBSTRING(log_id, 3) AS UNSIGNED)), 0) FROM Logs")
    Integer findMaxLogId();

}
